import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

// 使用ThreadPoolExecutor创建一个忽略最新任务的线程池，创建规则：
// 核心线程数为5   最大线程数为10   任务队列为100   拒绝策略为忽略最新任务
public class Test2 {
    public static void main(String[] args) {
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(5,10,
                8, TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(100),
                new ThreadPoolExecutor.DiscardPolicy());

        // 测试执行
        for (int i = 1; i <= 1000; i++) {
            new Thread(() -> {
                System.out.println(Thread.currentThread().getName() + " 已执行");
            },"Thread-"+(i)).start();
        }
    }
}
